package it.univaq.di.helpdesk.business.model;

import java.io.Serializable;

public abstract class Device implements Serializable, Comparable<Device> {
	private int deviceID;
	private String type;
	private String name;
	private String model;
	private String vendor;
	private String size;
	private int parentDeviceID;
	
	@Override
	public int compareTo(Device o) {
		int result = 0;
		
		if (this.deviceID < o.deviceID) {
			result = -1;
		} else if (this.deviceID > o.deviceID) {
			result = 1;
		}
		
		return result;
	}

	/**
	 * Used to return a composite in the hierarchy
	 * 
	 * @return A composite device or null if called on component
	 */
	public abstract Device getComposite();
	
	public static final Device getInstanceOf(String deviceType) {
		Device device = null;
		
		if ("Computer".equals(deviceType)) {
			device = new Computer();
		} else if("Software".equals(deviceType)) {
			device = new Software();
		} else if ("Hardware".equals(deviceType)) {
			device = new Hardware();
		} else if ("Printer".equals(deviceType)) {
			device = new Printer();
		}
		
		return device;
	}
	
	protected Device() {
		super();
	}

	public int getDeviceID() {
		return deviceID;
	}

	public void setDeviceID(int deviceID) {
		this.deviceID = deviceID;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getModel() {
		return model;
	}

	public void setModel(String model) {
		this.model = model;
	}

	public String getVendor() {
		return vendor;
	}

	public void setVendor(String vendor) {
		this.vendor = vendor;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public void setParentDeviceID(int parentDeviceID) {
		this.parentDeviceID = parentDeviceID;
	}

	public int getParentDeviceID() {
		return parentDeviceID;
	}
}
